﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DLMemberPointMS.Entity.POCOModel;
using DLMemberPointMS.Entity.ViewModel;
using DLMemberPointMS.Common;
using DLMemberPointMS.Business;
namespace DLMemberPointMS.Web.Controllers
{
    public class ExchangGiftController : Controller
    {
        private  LExchangGiftService LExchangGiftService = new LExchangGiftService();
        //加载页面
        // GET: ExchangGift
        public ActionResult Index(string idOrPhone)
        {
         
                return View();
            
           
           
        }
       
        public ActionResult GetExchangGiftList(PageViewModels pageModel)
        {
           
            #region Buiness加载信息列表
            var resault = LExchangGiftService.GetExGift(pageModel);
            return Json(resault, JsonRequestBehavior.AllowGet);
            #endregion


            #region 普通加载列表信息
            //var db = new DLMPMSModel();
            //pageModel.page = pageModel.page - 1 < 1 ? 1 : pageModel.page;

            //var list = db.ExchangGifts.OrderBy(g=>g.EG_ID).AsQueryable().Skip((pageModel.page - 1) * pageModel.limit).Take(pageModel.limit).Select(g => new ExchangGiftViewModel()
            //{
            //    EG_ID=g.EG_ID,
            //    EG_GiftCode=g.EG_GiftCode,
            //    EG_GiftName=g.EG_GiftName,
            //    EG_Point=g.EG_Point,
            //    EG_Number=g.EG_Number,
            //    EG_ExchangNum=g.EG_ExchangNum,
            //    EG_Remark=g.EG_Remark
            //}).ToList();
            //int count = list.Count();
            //OperateResult resault = null;
            //if (list==null)
            //{
            //    resault = new OperateResult(code.Error, "没有数据哟！") ;
            //}
            //else
            //{
            //    resault = new OperateResult(code.Success,count,"查询成功",list);

            //}
            //return Json(resault,JsonRequestBehavior.AllowGet);
            #endregion
        }
        //加载会员信息
        public ActionResult GetMemCardInfo(string idOrPhone)
        {
            #region Buiness加载信息列表

               var  resault = LExchangGiftService.GetMemCard(idOrPhone);
        
                return Json(resault, JsonRequestBehavior.AllowGet);

            #endregion
        }



        // GET: ExchangGift/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }
        [HttpPost]
        // GET: ExchangGift/Create
        public ActionResult Create2(string MC_ID,string MC_CardID,int EG_ID,string CO_GavePoint)
        {
            LConsumeOrdersService ConsumeOrders = new LConsumeOrdersService();
           var resault= ConsumeOrders.InsertExgift(MC_ID, MC_CardID, EG_ID, CO_GavePoint);
            return Json(resault, JsonRequestBehavior.AllowGet);
        }
        //积分兑换
        public ActionResult DuiHuan()
        {
            return View();
        }
        // POST: ExchangGift/Create
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: ExchangGift/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: ExchangGift/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: ExchangGift/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: ExchangGift/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
